function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

var casConfig = null;

var Config = /*#__PURE__*/function () {
  function Config(config) {
    _classCallCheck(this, Config);

    this.data = config;
  }

  _createClass(Config, [{
    key: "get",
    value: function get(key) {
      var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

      if (key.indexOf('.') === -1) {
        if (this.data[key]) {
          return this.data[key];
        }

        return defaultValue;
      } else {
        var keyArr = key.split('.');
        return keyArr.reduce(function (obj, cur, i) {
          return obj[cur] ? obj[cur] : defaultValue;
        }, this.data);
      }
    }
  }, {
    key: "set",
    value: function set(key, value) {
      if (key.indexOf('.') === -1) {
        this.data[key] = value;
      } else {
        var keyArr = key.split('.'),
            tmp = {},
            oldData = this.data;
        keyArr.reduce(function (obj, cur, i) {
          return obj[cur] = i === keyArr.length - 1 ? value : obj[cur] || {};
        }, tmp);
        this.data = _objectSpread(_objectSpread({}, oldData), tmp);
      }

      this.data[key] = value;
    }
  }, {
    key: "remove",
    value: function remove(key) {
      delete this.data[key];
    }
  }, {
    key: "removeAll",
    value: function removeAll() {
      this.data = undefined;
    }
  }, {
    key: "all",
    value: function all() {
      return this.data;
    }
  }, {
    key: "getPipe",
    value: function getPipe(arr, data, defaultValue) {
      var tmpData = data[arr.splice(0, 1)[0]];

      if (arr.length == 0) {
        return tmpData;
      } else {
        if (tmpData) {
          return this.getPipe(arr, tmpData, defaultValue);
        } else {
          return defaultValue;
        }
      }
    }
  }]);

  return Config;
}();

export default function (config) {
  casConfig = new Config(config);
  return casConfig;
}
export { casConfig };